home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C23 / Trmnator.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  720 b   |  39 lines

  1. //: C23:Trmnator.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Use of set_terminate()
  7. // Also shows uncaught exceptions
  8. #include <exception>
  9. #include <iostream>
  10. #include <cstdlib>
  11. using namespace std;
  12.  
  13. void terminator() {
  14.   cout << "I'll be back!" << endl;
  15.   abort();
  16. }
  17.  
  18. void (*old_terminate)()
  19.   = set_terminate(terminator);
  20.  
  21. class Botch {
  22. public:
  23.   class Fruit {};
  24.   void f() {
  25.     cout << "Botch::f()" << endl;
  26.     throw Fruit();
  27.   }
  28.   ~Botch() { throw 'c'; }
  29. };
  30.  
  31. int main() {
  32.   try{
  33.     Botch b;
  34.     b.f();
  35.   } catch(...) {
  36.     cout << "inside catch(...)" << endl;
  37.   }
  38. } ///:~
  39.